package com.handa.common.utils;

import com.handa.common.entity.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class RequestContext {

    public static Authentication getAuthentication() {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    public static LoginUser getLoginUser() {
        try {
            Authentication authentication = getAuthentication();
            return authentication != null ? (LoginUser) authentication.getPrincipal() : null;
        } catch (Exception e) {
            return null;
        }
    }

}
